﻿using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SkyNote.Infrastructure.UnityExtensions
{
    public class UnityLifetimeManager : LifetimeManager
    {
        private string _key = string.Format(System.Globalization.CultureInfo.InvariantCulture, "PerCallContextLifeTimeManager_{0}", new object[]
		{
			System.Guid.NewGuid()
		});
        public override object GetValue()
        {
            return System.Runtime.Remoting.Messaging.CallContext.GetData(this._key);
        }
        public override void SetValue(object newValue)
        {
            System.Runtime.Remoting.Messaging.CallContext.SetData(this._key, newValue);
        }
        public override void RemoveValue()
        {
            System.Runtime.Remoting.Messaging.CallContext.FreeNamedDataSlot(this._key);
        }
    }
}
